package com.yipei.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yipei.business.domain.MlBankCard;
import com.yipei.business.mapper.MlBankCardMapper;
import com.yipei.business.service.IMlBankCardService;
import com.yipei.common.utils.DateUtils;
import com.yipei.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户银行Service业务层处理
 *
 * @author yipei
 * @date 2024-12-23
 */
@Service
public class MlBankCardServiceImpl extends ServiceImpl<MlBankCardMapper, MlBankCard>  implements IMlBankCardService
{
    @Autowired
    private MlBankCardMapper mlBankCardMapper;

    /**
     * 查询用户银行
     *
     * @param id 用户银行主键
     * @return 用户银行
     */
    @Override
    public MlBankCard selectMlBankCardById(Long id)
    {
        return mlBankCardMapper.selectMlBankCardById(id);
    }

    /**
     * 查询用户银行列表
     *
     * @param mlBankCard 用户银行
     * @return 用户银行
     */
    @Override
    public List<MlBankCard> selectMlBankCardList(MlBankCard mlBankCard)
    {
        return mlBankCardMapper.selectMlBankCardList(mlBankCard);
    }

    /**
     * 新增用户银行
     *
     * @param mlBankCard 用户银行
     * @return 结果
     */
    @Override
    public int insertMlBankCard(MlBankCard mlBankCard)
    {
        String tdAcc = SecurityUtils.getLoginMember().getMlTradeAccount().getTdAcc();
        mlBankCard.setTdAcc(tdAcc);
        mlBankCard.setCreateTime(DateUtils.getNowDate());
        mlBankCard.setRemarks("success");
        return mlBankCardMapper.insertMlBankCard(mlBankCard);
    }

    /**
     * 修改用户银行
     *
     * @param mlBankCard 用户银行
     * @return 结果
     */
    @Override
    public int updateMlBankCard(MlBankCard mlBankCard)
    {
        mlBankCard.setUpdateTime(DateUtils.getNowDate());
        return mlBankCardMapper.updateMlBankCard(mlBankCard);
    }

    /**
     * 批量删除用户银行
     *
     * @param ids 需要删除的用户银行主键
     * @return 结果
     */
    @Override
    public int deleteMlBankCardByIds(Long[] ids)
    {
        return mlBankCardMapper.deleteMlBankCardByIds(ids);
    }

    /**
     * 删除用户银行信息
     *
     * @param id 用户银行主键
     * @return 结果
     */
    @Override
    public int deleteMlBankCardById(Long id)
    {
        return mlBankCardMapper.deleteMlBankCardById(id);
    }

    @Override
    public List<MlBankCard> selectTdAccBankList() {
        String tdAcc = SecurityUtils.getLoginMember().getMlTradeAccount().getTdAcc();
        LambdaQueryWrapper<MlBankCard> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(MlBankCard::getTdAcc,tdAcc);
        return  this.list(lambdaQueryWrapper);
    }
}
